package io.coderyeah.ymcc.web.controller;

import io.coderyeah.ymcc.dto.GoodsDTO;
import io.coderyeah.ymcc.result.JSONResult;
import io.coderyeah.ymcc.service.ITrolleyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lqs
 * @date 2022/11/6 10:08
 */
@RestController
@RequestMapping("/trolley")
public class TrolleyController {
    @Autowired
    private ITrolleyService trolleyService;

    @PostMapping("/save")
    public JSONResult save(@RequestBody GoodsDTO goodsDTO) {
        trolleyService.save(goodsDTO);
        return JSONResult.success();
    }

    @GetMapping("/query/{userId}")
    public JSONResult queryByUserId(@PathVariable Long userId) {
        List<GoodsDTO> goodsDTOS = trolleyService.queryByUserId(userId);
        return JSONResult.success(goodsDTOS);
    }

    @DeleteMapping("/delete/{userId}/{goodsId}")
    public JSONResult delete(@PathVariable("userId") Long userId, @PathVariable("goodsId") Long goodsId) {
        trolleyService.delete(userId, goodsId);
        return JSONResult.success();
    }
}
